package com.demo05.socket.m2;

import java.io.*;
import java.net.Socket;

/**
 * @Author: root
 * @Date: 2018/11/25 1:45
 */
public class Client {
    final static int PORT = 8766;
    final static String ADDR = "127.0.0.1";

    public static void main(String[] args) {
        Socket socket = null;
        PrintWriter writer = null;
        BufferedReader in = null;
        try {
            socket = new Socket(ADDR, PORT);
            writer = new PrintWriter(socket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            writer.println("我是client，给你发送的数据1234567890.......");
            String response = in.readLine();
            System.out.println("Client: " + response);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

            try {
                writer.close();
                in.close();
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
